package pac1_rgr;

import process.Actor;
import widgets.ChooseRandom;

public class GenerBarge extends Actor{
	

	private ChooseRandom rnd;
	private double finishTime;
	private Main gui;
	private Model model;

	public GenerBarge(String string, Main gui, Model model) {
		this.setNameForProtocol(string);
		rnd = gui.getChooseRandomBarge();
		finishTime = gui.getChooseDataModelTime().getDouble();
		this.gui=gui;
		this.model=model;
	}

	@Override
	protected void rule() {
		int countBarge=0;
		while(true){
			holdForTime(rnd.next());
			if(getDispatcher().getCurrentTime()>=finishTime){
				return;
			}
			countBarge++;
			String name="Баржа"+String.valueOf(countBarge);
			getDispatcher().printToProtocol(" прийшла "+name);
			Barge b= new Barge(name, gui, model);
			getDispatcher().printToProtocol(" створена "+b);
			getDispatcher().addStartingActor(b);
			
		}
		
	}

}
